var http = require("../service/masterHttp.js");
var mc = require("../utils/messageCenter.js");
var eventData = require("../service/eventData.js");
var modal = require("../utils/alert.js");
var user = require("../service/userInfo.js");
var util = require("../utils/util.js");
var log = require("../utils/log.js");
var storeUtil = require("../service/storeUtil.js");
var loginUtil = require("../service/loginUtil.js");
let map = require("../utils/qqmap-wx-jssdk.min.js");
let config = require("../config.js");
let color = require("../service/colorUtil.js");

var _app;
var _finished = false;

function init(value) {
  if (!_finished) {
    _finished = true;
    _app = value;
    initModule();
  }
}

function initModule() {
  //Lenovo数据请求初始化
  http.init(_app);
  //注册消息中心
  _app.regMC = mc.reg;
  //模板消息的formID初始化
  storeUtil.init(_app);
  color.init(_app);
  //提示消息初始化
  modal.init();
  //事件常量
  _app.eventData = eventData;
  //注册日志打印工具
  _app.log = log.trace;
  // 注册统一http入口
  _app.request = http.request;
  _app.requestBase = http.requestBase;
  // 注册用户工具_app
  _app.user = user;
  _app.confirm = modal.confirm;
  // 注册获取数据时提示框的显示 
  _app.alert = modal.alert;
  _app.alertFun = modal.alertFun;
  _app.toast = modal.toast;
  _app.util = util;
  //formId工具方法
  _app.sendFromId = storeUtil.sendFormId;

  //发送全局消息
  _app.sendG = mc.sendG
  //登录辅助类
  _app.loginUtil = loginUtil;
  _app.map = map;
  _app.config = config;
  _app.color = color;
}
module.exports = {
  init: init
}